const install = (Vue, vm) => {
	Vue.prototype.navTo = (url,data) => {
		vm.$store.commit("com/setRouterData",data)
		uni.navigateTo({
			url
		})
	}
	
	Vue.prototype.showToast = (title) => {
		uni.showToast({
			title,
			icon: "none"
		})
	}
	
	Vue.prototype.dictFilter = (datas) => {
		let obj = [];
		datas.forEach(item => {
			obj[item.dictValue] ={
				txt:item.dictLabel,
				val:item.dictValue
			}
		})
		return obj;
	}
	
	Vue.prototype.getStatusBarHeight = () => {
		let statusBarHeight=0
		const info = uni.getSystemInfoSync()
		// 设置状态栏高度（H5顶部无状态栏小程序有状态栏需要撑起高度）
		statusBarHeight = info.statusBarHeight
		// 除了h5 app mp-alipay的情况下执行
		// #ifndef H5 || APP-PLUS || MP-ALIPAY
		// 获取胶囊的位置
		const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
		console.log("menuButtonInfo", menuButtonInfo);
		// (胶囊底部高度 - 状态栏的高度) + (胶囊顶部高度 - 状态栏内的高度) = 导航栏的高度
		statusBarHeight = (menuButtonInfo.bottom - info.statusBarHeight) + (menuButtonInfo.top - info
			.statusBarHeight)
		// #endif
		statusBarHeight *= 2
		return statusBarHeight;
	}
	
	Vue.prototype.isEmpty = (val) => {
		// null or undefined
		if (val == null) return true;
	
		if (typeof val === 'boolean') return false;
	
		if (typeof val === 'number') return !val;
	
		if (val instanceof Error) return val.message === '';
	
		switch (Object.prototype.toString.call(val)) {
			// String or Array
			case '[object String]':
			case '[object Array]':
				return !val.length;
				// Map or Set or File
			case '[object File]':
			case '[object Map]':
			case '[object Set]': {
				return !val.size;
			}
			// Plain Object
			case '[object Object]': {
				return !Object.keys(val).length;
			}
		}
	
		return false;
	}
	
	
	
	Vue.prototype.toTree=(data)=> {
		let result = []
		if (!Array.isArray(data)) {
			return result
		}
		data.forEach(item => {
			delete item.children;
		});
		let map = {};
		data.forEach(item => {
			map[item.id] = item;
		});
		data.forEach(item => {
			let parent = map[item.parentId];
			if (parent) {
				(parent.children || (parent.children = [])).push(item);
			} else {
				result.push(item);
			}
		});
		return result;
	}
	
	
}

export default {
	install
}